package 早晨练习0315;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class MorningPractice {
    /**
     * 1.有Student学生实体，包含姓名，班级名称，考试成绩,年龄四个属性，
     * 向集合中添加五个完整的学生对象（包含所有属性值），遍历集合，输出所有学生的信息。
     */

    /**
     * 2.根据学生的年龄和考试成绩排序(先按照考试成绩排,考试成绩相同再按照年龄排序
     */

    public static class Student {
        public String name;
        public int classN;
        public String score;
        public int age;

        public Student(String name, int classN, String score, int age) {
            this.name = name;
            this.classN = classN;
            this.score = score;
            this.age = age;
        }

        @Override
        public String toString() {
            return "{" +
                    "name='" + name + '\'' +
                    ", classN='" + classN + '\'' +
                    ", score='" + score + '\'' +
                    ", age='" + age + '\'' +
                    '}';
        }
    }

    public static void main(String[] args) {
        //01
        List<Student> students = new ArrayList<>();
        students.add(new Student("xiaohong", 2, "95.5", 18));
        students.add(new Student("xaohao", 3, "85.5", 16));
        students.add(new Student("haojian", 4, "75.5", 21));
        students.add(new Student("wangwangyi", 5, "75.5", 20));
        students.add(new Student("wushifan", 6, "55.5", 11));
                students.forEach(elem-> System.out.println(elem.toString()));

                System.out.println();

                //02
                students.stream().sorted((o1, o2) -> {
                    int result = o2.score.compareTo(o1.score);
                    if (result == 0) {
                return o2.age - o1.age;
            }
            return result;
        }).collect(Collectors.toList()).forEach(s -> System.out.println(s.toString()));
    }
}
